﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Phoenix.Installer;
using System.Xml;
using PServiceBus.Core.Runtime.Configuration;

namespace PServiceBus.ComponentContainer {
    public class ServiceInstaller : IServiceInstaller {
        #region IServiceInstaller Members

        public IEnumerable<ServiceInstallerInfo> Services {
            get {
                return ConfigurationParser.Process("configurations.xml")
                    .Select(x => x["config"] as Dictionary<string, object>)
                    .Select(x => x.ToDictionary(kv => kv.Key, kv => kv.Value == null ? string.Empty : kv.Value.ToString()))
                    .Select(element => new ServiceInstallerInfo()
                    {
                        Name = element["name"],
                        Description = element["description"],
                        DependOn = element.ContainsKey("dependon") ? element["dependon"] : string.Empty,
                        ExeFileName = "PServiceBus.ComponentContainer.exe"
                    });
            }
        }

        #endregion
    }
}
